/**
 * author: redd
 * create_time: 2018/1/2 15:53
 * description:
 */
 

var VSHADER_SOURCE =
  'attribute vec4 a_Position;\n' +  //存储限定符 类型 变量名
  'attribute float a_PointSize;\n' +
  'void main(){\n' +
  ' gl_Position = a_Position;\n' +
  ' gl_PointSize = a_PointSize;\n' +
  '}\n';

var FSHADER_SOURCE =
  'void main(){\n' +
  ' gl_FragColor = vec4(0.0, 1.0, 1.0, 1.0);\n' +
  '}\n';

function main() {
  var canvas = document.getElementById('webgl');
  var gl = getWebGLContext(canvas);
  if(!gl) {
    console.log('failed to get the rendering context');
    return;
  }

  if(!initShaders(gl, VSHADER_SOURCE, FSHADER_SOURCE)) {
    console.log('failed to initialize shaders.');
    return;
  }


  // 获取attribute变量的存储位置
  var a_Position = gl.getAttribLocation(gl.program, 'a_Position');
  if (a_Position < 0) {
    console.log('failed to get the storage location of a_Position');
    return;
  }

  var a_PointSize = gl.getAttribLocation(gl.program, 'a_PointSize');

  // 将顶点位置传输给attribute变量
  gl.vertexAttrib3f(a_Position, 0.0, 0.0, 0.0);
  gl.vertexAttrib1f(a_PointSize, 5.0);


  //设置canvas背景色
  gl.clearColor(0, 0, 0, 1.0);
  //清空canvas
  gl.clear(gl.COLOR_BUFFER_BIT);
  //绘制一个点
  gl.drawArrays(gl.POINTS, 0, 1);
}


